package com.augurit.gzcgwsp.csshlj.service.impl;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.VerticalAlignment;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.history.HistoryTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;

import com.augurit.common.system.web.auth.form.LoginUserForm;
import com.augurit.common.util.PageUtils;
import com.augurit.common.util.lang.StringUtils;
import com.augurit.gzcgwsp.commonex.util.lang.DateUtilsEX;
import com.augurit.gzcgwsp.csshlj.convert.YwSyShljysBaConvertor;
import com.augurit.gzcgwsp.csshlj.dao.ShljYsBaDao;
import com.augurit.gzcgwsp.csshlj.dao.ShljYsDao;
import com.augurit.gzcgwsp.csshlj.entity.ShljYsBa;
import com.augurit.gzcgwsp.csshlj.form.ShljYsBaForm;
import com.augurit.gzcgwsp.csshlj.form.ShljYsForm;
import com.augurit.gzcgwsp.csshlj.service.IShljYsBaService;
import com.augurit.gzcgwsp.csshlj.service.IShljYsService;
import com.augurit.gzcgwsp.excelimportexport.util.ExcelUtil;
import com.augurit.gzcgwsp.excelimportexport.util.GetFileName;
import com.augurit.gzcgwsp.sendNotice.service.IExchangeStateService;
import com.augurit.gzcgwsp.sendNotice.service.IYwMtbjlshInfoService;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceForWbService;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceInfoService;
import com.augurit.gzcgwsp.smartformCsdlwj.common.SmartDao;
import com.augurit.gzcgwsp.smartformCsdlwj.service.IYwHwXminfoService;
import com.augurit.gzcgwsp.wfex.common.service.IWfServiceEX;
import com.augurit.gzcgwsp.ywcmn.service.IYwComSjclService;
import com.augurit.smartform.service.IWfSupportService;
import com.augurit.wf.bi.convert.WfBusInstanceConvertor;
import com.augurit.wf.bi.service.IWfBusInstanceService;
import com.augurit.wf.bi.web.form.WfBusInstanceForm;
import com.augurit.wf.bi.web.form.WfBusInstanceTaskForm;
import com.augurit.wf.client.summary.web.form.WfTaskSummaryForm;
import com.augurit.wf.common.dao.Jbpm4HistTaskDao;
import com.augurit.wf.common.entity.WfBusInstance;
import com.augurit.wf.common.service.impl.WfBusClientServiceImpl;

/**
 * 目前这个类，只有与方欣的数据交换用到
 * @author Administrator
 *
 */

@Service
@Transactional
public class ShljYsBaServiceImpl extends WfBusClientServiceImpl<ShljYsBaForm> implements IShljYsBaService{

	private static final Logger log=Logger.getLogger(ShljYsBaServiceImpl.class);

	@Autowired
	private IWfSupportService wfSupportService;	
	@Autowired
	private SmartDao smartDao;	
	@Autowired
	private ShljYsBaDao shljYsBaDao;	
	@Autowired
	private IWfBusInstanceService wfBusInstanceService;	
	@Autowired
    private IYwComSjclService sjclService;	
	@Autowired
	private IYwHwXminfoService ywHwXminfoService;	
	@Autowired
	private Jbpm4HistTaskDao jbpm4HistTaskDao;	
	@Autowired
	private IShljYsService shljYsService;	
	@Autowired
	private ShljYsDao shljYsDao;
	@Autowired
    private IYwMtbjlshInfoService ywMtbjlshInfoService;
    @Autowired
	private IYwWebserviceInfoService ywWebserviceInfoService;
    @Autowired
    private IYwWebserviceForWbService ywWebserviceForWbService;
    @Autowired
    private IExchangeStateService exchangeStateService;
    @Autowired
    private IWfServiceEX wfServiceEX;
	
	public Page<ShljYsBaForm> search(Page<ShljYsBaForm> page,
			List<PropertyFilter> filters) {
		// TODO Auto-generated method stub
		return null;
	}

	public Page<ShljYsBaForm> search(Page<ShljYsBaForm> page, ShljYsBaForm form) {
		// TODO Auto-generated method stub
		return null;
	}

	public void delete(Long... ids) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * ��������ȡForm����
	 */
	@Transactional(readOnly = true)
	public ShljYsBaForm get(Long id) {
		ShljYsBa entity=(ShljYsBa)shljYsBaDao.get(id);
		ShljYsForm qsForm =	shljYsService.getForm(entity.getSyysid(), "SYSHLJ_V1");//.get(entity.getSyysid());
		//qsForm = getForm(entity, "SYSHLJ_V1", qsForm);		
		ShljYsBaForm form=YwSyShljysBaConvertor.convertVoToForm(entity, qsForm);
		form.setProjectName(entity.getProjectName());
		return form;
	}
	
	public ShljYsForm getForm(ShljYsBa entity, String tablename ,ShljYsForm form) {
		String sql=" select *　from "+tablename+" where id="+entity.getSyysid();
		List list=shljYsDao.queryForList(sql);
		  if(list!=null && list.size()>0){
   		   Map<String,String> map=(Map<String,String>) list.get(0);
             form.setSqdw(map.get("qymc"));
             form.setZsbh(map.get("fzh"));
             form.setYyzch(map.get("yyzzzch"));
             form.setFddbr(map.get("frdb"));
             form.setQybh(map.get("qybh"));
//             form.setProjectName(map.get("projectname"));
//             form.setXkContent((map.get("xkcontent")));
             
             form.setProjectName(map.get("xmmc"));//项目名称
             form.setXkContent((map.get("xkcontent")));
             String startDate=map.get("jysjsstr");//经营开始时间
             String endDate=map.get("jysjestr");//经营结束时间
             String fzsj=map.get("fzsjstr");//发证时间
             if(StringUtils.isBlank(map.get("xkcontent"))){
            	 form.setXkContent("城市生活垃圾经营性清扫、收集、运输");
             }
             if(StringUtils.isNotBlank(startDate) && startDate.length()>=10){
     			form.setStartYear(startDate.substring(0,4));
     			form.setStartMonth(startDate.substring(5,7));
     			form.setStartDay(startDate.substring(8,10));
     		 }else{
     			form.setStartYear(DateUtilsEX.getCurYear());
     			form.setStartMonth(DateUtilsEX.getCurMonth());
     			form.setStartDay(DateUtilsEX.getCurDay());
     		 }
             if(StringUtils.isNotBlank(endDate) && endDate.length()>=10){
            	   form.setEndYear(endDate.substring(0,4));
        			form.setEndMonth(endDate.substring(5,7));
        			form.setEndDay(endDate.substring(8,10));
      		}else{
      			form.setEndYear(DateUtilsEX.getCurYear());
      			form.setEndMonth(DateUtilsEX.getCurMonth());
      			form.setEndDay(DateUtilsEX.getCurDay());
      		}
            if(StringUtils.isNotBlank(fzsj) && fzsj.length()>=10){
       			form.setFzYear(fzsj.substring(0,4));
       			form.setFzMonth(fzsj.substring(5,7));
       			form.setFzDay(fzsj.substring(8,10));
       		}else{
    			form.setFzYear(DateUtilsEX.getCurMonth());
      			form.setFzMonth(DateUtilsEX.getCurMonth());
      			form.setFzDay(DateUtilsEX.getCurDay());
       		}
             form.setJdTel(map.get("jdtel"));
             form.setAddress(map.get("address"));
             form.setQyMaangerZw(map.get("qymaangerzw"));
             form.setQyManager(map.get("qymanager"));
             form.setQyManagerZc(map.get("qymanagerzc"));
             form.setQylx(map.get("qylx"));
             form.setQygyzb(map.get("qygyzb"));
             form.setQygrzb(map.get("qygrzb"));
             form.setQyhzzb(map.get("qyhzzb"));
             form.setQywszb(map.get("qywszb"));
             form.setFddbrZc(map.get("fddbrzc"));
             form.setFddbrZw(map.get("fddbrzw"));
             form.setAddress(map.get("address"));
             form.setZczb(map.get("zczb"));
             form.setFzrq(map.get("fzrq"));
             form.setFzjg(map.get("fzjg")==null?"广州市城市管理委员会":map.get("fzjg"));
             
             form.setCbyw(map.get("cbyw"));
             form.setSjr(map.get("sjr"));
             
             
 			//设置收件通知书书签
             form.setCbyw2(form.getCbyw());
             form.setCbyw3(form.getCbyw());
             form.setCbyw4(form.getCbyw());
             form.setFrdb2(form.getFddbr());
             form.setAcceptNo2(map.get("accept_no"));
//             String tbrqStr = simpleDateFormat.format(form.getTbrq());
             form.setTbrq2(map.get("tbrq"));
             //form.setTbrq3(map.get("tbrq"));
             form.setCurDate2(map.get("tbrq"));
             form.setCurDate3(map.get("tbrq"));
             form.setSjr2(form.getSjr());
             form.setSajg("广州市城市管理委员会");
             form.setSajg2(form.getSajg());
             form.setQymc2(form.getSqdw());
             form.setQymc(form.getSqdw());
             form.setFrdb(form.getFddbr());

             List list2 =new ArrayList();
             list2 = ywHwXminfoService.getFbXminfo(entity.getSyysid(), "ShljYs");
             list2.addAll(getfblist("shljsyba",entity.getSyysid()));
             list2.addAll(ywHwXminfoService.getFbXminfo(entity.getId(), "shljsyba"));
             if(list2!=null && list2.size()>0){
                 Map<String, String> map2 =(Map<String, String>) list2.get(0);
                 form.setXmid1(Long.parseLong(map2.get("xmid")));
                 form.setXmnr1(map2.get("xmnr"));
                 form.setStartday1(map2.get("startday"));
                 form.setEndday1(map2.get("endday"));
                 form.setGzsj1(map2.get("gzsj"));
                 if(list2.size()>1){
                	 map2 =(Map<String, String>) list2.get(1);
                     form.setXmid2(Long.parseLong(map2.get("xmid")));
                     form.setXmnr2(map2.get("xmnr"));
                     form.setStartday2(map2.get("startday"));
                     form.setEndday2(map2.get("endday"));
                     form.setGzsj2(map2.get("gzsj"));
                 }
                 if(list2.size()>2){
                	 map2 =(Map<String, String>) list2.get(2);
                     form.setXmid3(Long.parseLong(map2.get("xmid")));
                     form.setXmnr3(map2.get("xmnr"));
                     form.setStartday3(map2.get("startday"));
                     form.setEndday3(map2.get("endday"));
                     form.setGzsj3(map2.get("gzsj"));
                 }
                 if(list2.size()>3){
                	 map2 =(Map<String, String>) list2.get(3);
                     form.setXmid4(Long.parseLong(map2.get("xmid")));
                     form.setXmnr4(map2.get("xmnr"));
                     form.setStartday4(map2.get("startday"));
                     form.setEndday4(map2.get("endday"));
                     form.setGzsj4(map2.get("gzsj"));
                 }
                 if(list2.size()>4){
                	 map2 =(Map<String, String>) list2.get(4);
                     form.setXmid5(Long.parseLong(map2.get("xmid")));
                     form.setXmnr5(map2.get("xmnr"));
                     form.setStartday5(map2.get("startday"));
                     form.setEndday5(map2.get("endday"));
                     form.setGzsj5(map2.get("gzsj"));
                 }
                 if(list2.size()>5){
                	 map2 =(Map<String, String>) list2.get(5);
                     form.setXmid6(Long.parseLong(map2.get("xmid")));
                     form.setXmnr6(map2.get("xmnr"));
                     form.setStartday6(map2.get("startday"));
                     form.setEndday6(map2.get("endday"));
                     form.setGzsj6(map2.get("gzsj"));
                 }
             }
          }
		return form;
	}
	
	public  List getfblist(String templateCode,Long ysid) {
		Page<WfTaskSummaryForm> pageT = new Page<WfTaskSummaryForm>(10);
		List idlist = new ArrayList();
		try{
			Page pg = PageUtils.newPageInstance(pageT);
			// 查询语句及参数
			String tempHql = "select distinct inst, proc, temp.templateName, type.templateTypeName" +
					" from Jbpm4HistTask task, Jbpm4HistProcinst proc, WfBusInstance inst, WfBusTemplate temp, WfBusTemplateType type, ShljYsBa ysba" +
					" where task.procInstId = proc.procInstId and proc.procInstId = inst.procInstId" +
					" and inst.templateId = temp.id and temp.templateTypeId = type.id" +
					" and inst.masterEntityKey = ysba.id and temp.templateCode =:templateCode and ysba.syysid=:ysid" +
					" and proc.state=:procState and task.state=:taskState" +
					" order by proc.end asc" ;
			StringBuffer hql = new StringBuffer(tempHql);
			Map<String, Object> values = new HashMap();
			values.put("procState", HistoryProcessInstance.STATE_ENDED);
			values.put("taskState", HistoryTask.STATE_COMPLETED);
			values.put("templateCode", templateCode);
			values.put("ysid", ysid);
			// 执行分页查询操作
			jbpm4HistTaskDao.findPageByScrollMode(pg, hql.toString(), values);
			// 转换为Form对象列表并赋值到原分页对象中
	//		List<WfTaskSummaryForm> list = WfTaskSummaryConvertor.convertBusSummaryList(pg.getResult());
			List<Object[]> list = pg.getResult();
			if(list !=null && list.size()>0){
				for(Object[] objs : list){
					WfBusInstance inst  = (WfBusInstance)objs[0];
					if(inst!=null && inst.getMasterEntityKey()!=null){
						idlist.addAll( ywHwXminfoService.getFbXminfo(Long.parseLong(inst.getMasterEntityKey()), templateCode));
					}
				}
			}
			
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}		
		return idlist;
	}

	public void save(ShljYsBaForm... forms) {
		if(forms != null)
			for(ShljYsBaForm form : forms)
				this.save(form);
		
	}

	public void save(ShljYsBaForm form) {
        if (form == null) return;
		
        ShljYsBa entity = null;
		if(form != null && form.getId() != null){
			entity = shljYsBaDao.get(form.getId());
			if (StringUtils.isBlank(entity.getAcceptNo()) || form.getAcceptNo().indexOf("XXXX") > 0) 
			    form.setAcceptNo(null);
		}else{
			entity = new ShljYsBa();
            form.setAcceptNo(null);
		}
                
        boolean isNewForm = false;
        if (StringUtils.isBlank(form.getAcceptNo())) {
        	//生成政务中心统一查询编号 开始
			Map<String,String> serialNoAndPasswordMap = null;
        	if("Y".equals(form.getSendNotice())){//网办，1
        		serialNoAndPasswordMap = ywMtbjlshInfoService.getSerialNoAndPassword("1");
        	}else{//大厅，0
        		serialNoAndPasswordMap = ywMtbjlshInfoService.getSerialNoAndPassword("0");
        	}
        	String serialNo = serialNoAndPasswordMap.get("serialNo");
        	String password = serialNoAndPasswordMap.get("password");
			form.setSerialNo(serialNo);
			form.setPassword(password);
			form.setAcceptNo(serialNo);
    		//生成政务中心统一查询编号 结束
            isNewForm = true;        
        }
        YwSyShljysBaConvertor.convertFormToVo(form, entity);
        shljYsBaDao.save(entity);
		form.setId(entity.getId());
		if (isNewForm) {
		    sjclService.updateByNewForm(form.getId());
		}
		
	}

	/*
	 * 新增(non-Javadoc)
	 * @see com.augurit.gzcgwsp.csshlj.service.IShljYsService#wfBusSave(javax.servlet.http.HttpServletRequest, com.augurit.gzcgwsp.csshlj.form.ShljYsForm, java.util.Map, java.lang.String)
	 */
	public WfBusInstanceTaskForm wfBusSave(HttpServletRequest request,
			ShljYsForm form, Map map, String username) {
		WfBusInstanceTaskForm task = wfSupportService.wfBusSave(request);
		if(task==null)
			return null;
		
			String entityKey = task.getMasterEntityKey();
			String ysl = (String) map.get("ysl");
			String sqdw = (String) map.get("qymc"); // 申请单位
			String acceptNo = updateAcceptNoAndSumary(entityKey, sqdw, ysl,username); // 更新入受理号以及汇总字段
			Long id = null;
			if (task != null && task.getMasterEntityKey() != null) {
				id = Long.valueOf(task.getMasterEntityKey());
			}
			form.setId(id);
			task.setMessage(acceptNo); //设置受理编号
			if (ysl.equals("1")) { // 更新预受理状态
				changeYslState(id, 2l,null);
			}
			form.setId(id);
			
			//构造map
			String syysid=(String) map.get("syysid");//水域垃圾id
            
			return task;
	}
	
	/**
	 * 更新受理编号和汇总字段
	 * @param entityKey
	 * @return
	 */
	private String updateAcceptNoAndSumary(String entityKey, String sqdw,
			String ysl,String username) {
		String acceptNo = "";
		if (entityKey != null && entityKey.trim().length() > 0) {
			String sql = "SELECT ACCEPT_NO FROM  yw_syshljba t WHERE t.ID = "
					+ entityKey;
			List list = smartDao.getResultList(sql);
			if (list != null) {
				String bh = (String) list.get(0);
				if (bh == null || bh.trim().length() <= 0) {
					//生成政务中心统一查询编号 开始
					Map<String,String> serialNoAndPasswordMap = null;
		        	serialNoAndPasswordMap = ywMtbjlshInfoService.getSerialNoAndPassword("0");//大厅
		        	String serialNo = serialNoAndPasswordMap.get("serialNo");
		        	String password = serialNoAndPasswordMap.get("password");
		        	//生成政务中心统一查询编号 结束
		        	acceptNo = serialNo;
					String updateSql = "UPDATE yw_syshljba t SET t.ACCEPT_NO = '"
							+ serialNo
							+ "',t.SERIAL_NO='"
							+ serialNo
							+"',t.PASSWORD='"
							+ password
							+ "',t.SJR='"
							+ username
							+ "' WHERE t.ID = " + entityKey;
					smartDao.executeSql(updateSql);
					// =====================更新完受理编号========

					// =====================更新汇总字段===========
					WfBusInstance entity = wfBusInstanceService
							.getByMasterEntityAndKey("yw_syshljba", entityKey);
					entity.setBusMemo1(sqdw);
					entity.setBusMemo3(acceptNo);
					entity.setBusMemo4("从事水域城市生活垃圾经营性清扫、收集、运输服务许可审批备案");
					entity.setBusDate2(new Date());
					WfBusInstanceForm form = WfBusInstanceConvertor
							.convertVoToForm(entity);
					wfBusInstanceService.save(form);

				} else if ((bh != null && bh.trim().length() > 0) && ysl.equals("1")) { // 预受理，汇总字段
					
					//设置收件人  开始
					String updateSql = "UPDATE yw_syshljba t SET t.SJR='"
						+ username
						+ "' WHERE t.ID = " + entityKey;
					smartDao.executeSql(updateSql);
					//设置收件人  结束
					acceptNo = bh;
					WfBusInstance entity = wfBusInstanceService
							.getByMasterEntityAndKey("yw_syshljba", entityKey);
					entity.setBusMemo1(sqdw);
					entity.setBusMemo3(acceptNo);
					entity.setBusMemo4("从事水域城市生活垃圾经营性清扫、收集、运输服务许可审批备案");
					entity.setBusDate2(new Date());
					WfBusInstanceForm form = WfBusInstanceConvertor
							.convertVoToForm(entity);
					wfBusInstanceService.save(form);

				} else {
					acceptNo = bh;
				}
			}
		}
		return acceptNo;
	}
	
	public void changeYslState(Long id,Long state,String yslThyy) {
    	StringBuffer sql = new StringBuffer();
    	sql.append("update ShljYsBa t set t.ysl='"+state+"' ");
    	if(StringUtils.isNotBlank(yslThyy)){
    		sql.append(" ,t.yslThyy='"+yslThyy+"'");
    	}
    	sql.append(" where t.id="+id);
    	shljYsBaDao.getSession().createQuery(sql.toString()).executeUpdate();
    	System.out.println("水域备案收件");
    }
    
	/**
	 * 保存副本第一页
	 */
	public void saveFb(Map map) {
		this.saveBaseInfo(map);		
	}
	/**
	 * 保存副本其他信息
	 * @param map
	 */
	private void saveBaseInfo(Map map){
		JSONObject jsonObject = JSONObject.fromObject(map); 
		ShljYsForm lyForm=(ShljYsForm) JSONObject.toBean(jsonObject, ShljYsForm.class);
		Long lyYwId=(Long) map.get("syYwId");
		lyForm.setId(lyYwId);
		this.shljYsService.doUpdateFb(lyForm,"syshlj_v1");	
	}
	
	/**
	 * 保存副本第二页
	 */
	public void saveFb2(Map map) {
		StringBuffer sb=new StringBuffer(" update syshlj_v1 set ");
		JSONObject jsonObject = JSONObject.fromObject(map); 
		ShljYsForm form=(ShljYsForm) JSONObject.toBean(jsonObject, ShljYsForm.class);
		Long lyYwId=(Long) map.get("syYwId");
		form.setId(lyYwId);
		if(StringUtils.isNotBlank(form.getXmnr4())){
			sb.append(" xmnr4='"+form.getXmnr4()+"', ");//项目名称
			sb.append(" startday4='"+form.getStartday4()+"', ");//项目记录
			sb.append(" endday4='"+form.getEndday4()+"',");//项目记录
			if(StringUtils.isNotBlank(form.getXmnr5())){
				sb.append(" gzsj4='"+form.getGzsj4()+"', ");//项目记录
			}else{
				sb.append(" gzsj4='"+form.getGzsj4()+"'");//项目记录
			}
			
		}
		if(StringUtils.isNotBlank(form.getXmnr5())){
			sb.append(" xmnr5='"+form.getXmnr5()+"', ");//项目名称
			sb.append(" startday5='"+form.getStartday5()+"', ");//项目记录
			sb.append(" endday5='"+form.getEndday5()+"',");//项目记录
			if(StringUtils.isNotBlank(form.getXmnr6())){
				sb.append(" gzsj5='"+form.getGzsj5()+"', ");//盖章时间
			}else{
				sb.append(" gzsj5='"+form.getGzsj5()+"'");//盖章时间
			}
			
		}
		if(StringUtils.isNotBlank(form.getXmnr6())){
			sb.append(" xmnr6='"+form.getXmnr6()+"', ");//项目名称
			sb.append(" startday6='"+form.getStartday6()+"', ");//项目记录
			sb.append(" endday6='"+form.getEndday6()+"',");//项目记录
			if(StringUtils.isNotBlank(form.getXmnr7())){
				sb.append(" gzsj6='"+form.getGzsj6()+"',");//盖章时间
			}else{
				sb.append(" gzsj6='"+form.getGzsj6()+"'");//盖章时间
			}
		}
		if(StringUtils.isNotBlank(form.getXmnr7())){
			sb.append(" xmnr7='"+form.getXmnr7()+"', ");//项目名称
			sb.append(" startday7='"+form.getStartday7()+"', ");//项目记录
			sb.append(" endday7='"+form.getEndday7()+"',");//项目记录
			if(StringUtils.isNotBlank(form.getXmnr8())){
				sb.append(" gzsj7='"+form.getGzsj7()+"', ");//盖章时间
			}else{
				sb.append(" gzsj7='"+form.getGzsj7()+"'");//盖章时间
			}
		}
		if(StringUtils.isNotBlank(form.getXmnr8())){
			sb.append(" xmnr8='"+form.getXmnr8()+"', ");//项目名称
			sb.append(" startday8='"+form.getStartday8()+"', ");//项目记录
			sb.append(" endday8='"+form.getEndday8()+"',");//项目记录
			if(StringUtils.isNotBlank(form.getXmnr9())){
				sb.append(" gzsj8='"+form.getGzsj8()+"', ");//盖章时间
			}else{
				sb.append(" gzsj8='"+form.getGzsj8()+"'");//盖章时间
			}
		}
		if(StringUtils.isNotBlank(form.getXmnr9())){
			sb.append(" xmnr9='"+form.getXmnr9()+"', ");//项目名称
			sb.append(" startday9='"+form.getStartday9()+"', ");//项目记录
			sb.append(" endday9='"+form.getEndday9()+"',");//项目记录
			sb.append(" gzsj9='"+form.getGzsj9()+"'");//盖章时间
		}
		sb.append(" where id="+form.getId());
		shljYsDao.updateDateBase(sb.toString());
	}
	
	/*
	 * 打印副本
	 * @see com.augurit.gzcgwsp.csshlj.service.IShljYsBaService#writeFbData(com.augurit.gzcgwsp.csshlj.form.ShljYsBaForm, java.lang.String, java.lang.String)
	 */
	public String writeFbData(ShljYsBaForm form, String context, String inpath) {
		inpath=inpath.replace("/", File.separator);
        String tempOutPath="Templates/csshlj/outfile/xkzfb/outfile";
        String fileName = GetFileName.getFileName("xls");
        tempOutPath=this.buildPath(tempOutPath, fileName);
        String outfilepath=context+"/"+tempOutPath;
        outfilepath=outfilepath.replace("/", File.separator);
        String outdir=outfilepath.substring(0,outfilepath.lastIndexOf(File.separator));
        File file=new File(outdir);
        if(!file.exists()){
            file.mkdirs();
        }
        ShljYsForm forms=this.shljYsService.getForm(form.getSyysid(),"SYSHLJ_V1");
        forms.setXkContent("广州市（水域）城市生活垃圾经营性清扫（捞）、收集");
        writerFbDataExcel(inpath,outfilepath,forms);
        
		return tempOutPath;
	}
    /**
     * 生成后面的文件路径加上年月
     * @param realpath 定义的目录
     * @param fileNamesuffix 文件后缀名
     * @return
     */
    private String buildPath(String realpath,String fileName){
        String dateDir = GetFileName.getDirector();
        return realpath+"/"+dateDir+"/"+fileName;
        
    }
    /**
     * 复制副本写入数据
     * @param inpath
     * @param outfilepath
     * @param form
     */
    private void writerFbDataExcel(String inpath, String outfilepath,
    		ShljYsForm form) {
        WritableWorkbook wwb;
        try {
            wwb = ExcelUtil.createWorkbookByOld(inpath, outfilepath);
            WritableSheet wsOne = ExcelUtil.getWritableSheetByIndex(wwb, 0);
            copyFbData(wsOne,form);
            WritableSheet wsTwo = ExcelUtil.getWritableSheetByIndex(wwb, 1);
            copyFbData2(wsTwo,form);//先屏蔽副本后面的地方
            wwb.write();
            wwb.close();
        } catch (Exception e) {
            log.error("写文件错误"+e);
        } 
    }
    
    /**
     * 写副本第二页数据
     * @param wsOne
     * @param form
     */
    private void copyFbData2(WritableSheet wsOne, ShljYsForm form) {
    	 try {    		 
    		 WritableCellFormat wcfBottomBorder = ExcelUtil.createCellFormat2("宋体", 10, Alignment.CENTRE, VerticalAlignment.CENTRE,false,null,null,null,Border.BOTTOM);
			 WritableCellFormat wcfxmnrLeftBorder = ExcelUtil.createCellFormat2("宋体", 10, Alignment.LEFT, VerticalAlignment.TOP,true,Border.LEFT,Border.RIGHT,null,null);
			 wcfBottomBorder.setLocked(false);
			 
			 String xmnr4 =form.getXmnr4();
			 xmnr4 = xmnr4.replaceAll("<br>", "\r\n");
             xmnr4 = xmnr4.replaceAll("&nbsp;", " ");
             xmnr4 += "\r\n  有效期限：";
             String startday4 = form.getStartday4();
             String endday4 = form.getEndday4();
             if(startday4 != null && startday4.length() > 0 && endday4 != null && endday4.length() > 0){
            	 xmnr4 += "从" + startday4 + "到" + endday4;
             }
			 ExcelUtil.modiStrCell2(wsOne,1, 3, xmnr4 == null?"":xmnr4, wcfxmnrLeftBorder);//项目记录4
			 if(StringUtils.isNotBlank(form.getGzsj4())){
				 String fzsj=form.getGzsj4();
            	 String year = fzsj.substring(0, 4);
            	 String month = fzsj.substring(5, 7);
            	 String day = fzsj.substring(8, 10);
    			 ExcelUtil.modiStrCell2(wsOne,11, 7, year==null?"":year, wcfBottomBorder);//项目盖章年
    			 ExcelUtil.modiStrCell2(wsOne,14, 7, month==null?"":month, wcfBottomBorder);//项目盖章月
    			 ExcelUtil.modiStrCell2(wsOne,16, 7, day==null?"":day, wcfBottomBorder);//项目盖章日
             }
			 
			 String xmnr5 =form.getXmnr5();
			 xmnr5 = xmnr5.replaceAll("<br>", "\r\n");
             xmnr5 = xmnr5.replaceAll("&nbsp;", " ");
             xmnr5 += "\r\n  有效期限：";
             String startday5 = form.getStartday5();
             String endday5 = form.getEndday5();
             if(startday5 != null && startday5.length() > 0 && endday5 != null && endday5.length() > 0){
            	 xmnr5 += "从" + startday5 + "到" + endday5;
             }
			 ExcelUtil.modiStrCell2(wsOne,1, 9, xmnr5 == null?"":xmnr5, wcfxmnrLeftBorder);//项目记录5
			 if(StringUtils.isNotBlank(form.getGzsj5())){
				 String fzsj=form.getGzsj5();
            	 String year = fzsj.substring(0, 4);
            	 String month = fzsj.substring(5, 7);
            	 String day = fzsj.substring(8, 10);
    			 ExcelUtil.modiStrCell2(wsOne,11, 17, year==null?"":year, wcfBottomBorder);//项目盖章年
    			 ExcelUtil.modiStrCell2(wsOne,14, 17, month==null?"":month, wcfBottomBorder);//项目盖章月
    			 ExcelUtil.modiStrCell2(wsOne,16, 17, day==null?"":day, wcfBottomBorder);//项目盖章日
             }
			 
			 String xmnr6 =form.getXmnr6();
			 xmnr6 = xmnr6.replaceAll("<br>", "\r\n");
             xmnr6 = xmnr6.replaceAll("&nbsp;", " ");
             xmnr6 += "\r\n  有效期限：";
             String startday6 = form.getStartday6();
             String endday6 = form.getEndday6();
             if(startday6 != null && startday6.length() > 0 && endday6 != null && endday6.length() > 0){
            	 xmnr6 += "从" + startday6 + "到" + endday6;
             }
			 ExcelUtil.modiStrCell2(wsOne,1, 19, xmnr6 == null?"":xmnr6, wcfxmnrLeftBorder);//项目记录6
			 if(StringUtils.isNotBlank(form.getGzsj6())){
				 String fzsj=form.getGzsj6();
            	 String year = fzsj.substring(0, 4);
            	 String month = fzsj.substring(5, 7);
            	 String day = fzsj.substring(8, 10);
    			 ExcelUtil.modiStrCell2(wsOne,11, 26, year==null?"":year, wcfBottomBorder);//项目盖章年
    			 ExcelUtil.modiStrCell2(wsOne,14, 26, month==null?"":month, wcfBottomBorder);//项目盖章月
    			 ExcelUtil.modiStrCell2(wsOne,16, 26, day==null?"":day, wcfBottomBorder);//项目盖章日
             }
			 
			 String xmnr7 =form.getXmnr7();
			 xmnr7 = xmnr7.replaceAll("<br>", "\r\n");
             xmnr7 = xmnr7.replaceAll("&nbsp;", " ");
             xmnr7 += "\r\n  有效期限：";
             String startday7 = form.getStartday7();
             String endday7 = form.getEndday7();
             if(startday7 != null && startday7.length() > 0 && endday7 != null && endday7.length() > 0){
            	 xmnr7 += "从" + startday7 + "到" + endday7;
             }
			 ExcelUtil.modiStrCell2(wsOne,21, 3, xmnr7 == null?"":xmnr7, wcfxmnrLeftBorder);//项目记录7
			 if(StringUtils.isNotBlank(form.getGzsj7())){
				 String fzsj=form.getGzsj7();
            	 String year = fzsj.substring(0, 4);
            	 String month = fzsj.substring(5, 7);
            	 String day = fzsj.substring(8, 10);
    			 ExcelUtil.modiStrCell2(wsOne,31, 7, year==null?"":year, wcfBottomBorder);//项目盖章年
    			 ExcelUtil.modiStrCell2(wsOne,34, 7, month==null?"":month, wcfBottomBorder);//项目盖章月
    			 ExcelUtil.modiStrCell2(wsOne,36, 7, day==null?"":day, wcfBottomBorder);//项目盖章日
             }
			 
			 String xmnr8 =form.getXmnr8();
			 xmnr8 = xmnr8.replaceAll("<br>", "\r\n");
             xmnr8 = xmnr8.replaceAll("&nbsp;", " ");
             xmnr8 += "\r\n  有效期限：";
             String startday8 = form.getStartday8();
             String endday8 = form.getEndday8();
             if(startday8 != null && startday8.length() > 0 && endday8 != null && endday8.length() > 0){
            	 xmnr8 += "从" + startday8 + "到" + endday8;
             }
			 ExcelUtil.modiStrCell2(wsOne,21, 9, xmnr8 == null?"":xmnr8, wcfxmnrLeftBorder);//项目记录8
			 if(StringUtils.isNotBlank(form.getGzsj8())){
				 String fzsj=form.getGzsj8();
            	 String year = fzsj.substring(0, 4);
            	 String month = fzsj.substring(5, 7);
            	 String day = fzsj.substring(8, 10);
    			 ExcelUtil.modiStrCell2(wsOne,31, 17, year==null?"":year, wcfBottomBorder);//项目盖章年
    			 ExcelUtil.modiStrCell2(wsOne,34, 17, month==null?"":month, wcfBottomBorder);//项目盖章月
    			 ExcelUtil.modiStrCell2(wsOne,36, 17, day==null?"":day, wcfBottomBorder);//项目盖章日
             }
			 
			 String xmnr9 =form.getXmnr9();
			 xmnr9 = xmnr9.replaceAll("<br>", "\r\n");
             xmnr9 = xmnr9.replaceAll("&nbsp;", " ");
             xmnr9 += "\r\n  有效期限：";
             String startday9 = form.getStartday9();
             String endday9 = form.getEndday9();
             if(startday9 != null && startday9.length() > 0 && endday9 != null && endday9.length() > 0){
            	 xmnr9 += "从" + startday9 + "到" + endday9;
             }
			 ExcelUtil.modiStrCell2(wsOne,21, 19, xmnr9 == null?"":xmnr9, wcfxmnrLeftBorder);//项目记录9
			 if(StringUtils.isNotBlank(form.getGzsj9())){
				 String fzsj=form.getGzsj9();
            	 String year = fzsj.substring(0, 4);
            	 String month = fzsj.substring(5, 7);
            	 String day = fzsj.substring(8, 10);
    			 ExcelUtil.modiStrCell2(wsOne,31, 26, year==null?"":year, wcfBottomBorder);//项目盖章年
    			 ExcelUtil.modiStrCell2(wsOne,34, 26, month==null?"":month, wcfBottomBorder);//项目盖章月
    			 ExcelUtil.modiStrCell2(wsOne,36, 26, day==null?"":day, wcfBottomBorder);//项目盖章日
             }
			 
//			 String xmnr =project.getXmcontent();
//             xmnr = xmnr.replaceAll("<br>", "\r\n");
//             xmnr = xmnr.replaceAll("&nbsp;", " ");
//             xmnr +="\r\n  有效期限：";
//             String startday = project.getStartday();
//             String endday = project.getEndday();
//             if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
//            	 xmnr +="从"+startday+"到"+endday;
//             }
//			 ExcelUtil.modiStrCell2(wsOne,1, 3, xmnr==null?"":xmnr, wcfxmnrLeftBorder);//项目内容
//             String fzsj = project.getGzsjday();
//             String year="";
//             String month="";
//             String day="";
//             if(fzsj!=null && fzsj.length()>4){
//            	 year = fzsj.substring(0, 4);
//            	 month = fzsj.substring(5, 7);
//            	 day = fzsj.substring(8, 10);
//    			 ExcelUtil.modiStrCell2(wsOne,11, 7, year==null?"":year, wcfBottomBorder);//变更盖章年
//    			 ExcelUtil.modiStrCell2(wsOne,14, 7, month==null?"":month, wcfBottomBorder);//变更盖章月
//    			 ExcelUtil.modiStrCell2(wsOne,16, 7, day==null?"":day, wcfBottomBorder);//变更盖章日
//             }
			 
//			 WritableCellFormat wcf2=ExcelUtil.createCellFormat("宋体", 10, Alignment.CENTRE, VerticalAlignment.CENTRE,false);
//			 WritableCellFormat wcfxmnr=ExcelUtil.createCellFormat("宋体", 10, Alignment.LEFT, VerticalAlignment.TOP,true);
//			 wcf2.setLocked(false);
//             List list2 =new ArrayList();
//             list2 = ywHwXminfoService.getFbXminfo(form.getId(), "shljys");
//             if(list2!=null && list2.size()>3){
//                 Map<String, String> map2 =(Map<String, String>) list2.get(3);
//                 String xmnr =map2.get("xmnr");
//                 xmnr = xmnr.replaceAll("<br>", "\r\n");
//                 xmnr = xmnr.replaceAll("&nbsp;", " ");
//                 xmnr +="\r\n  有效期限：";
//                 String startday = map2.get("startday");
//                 String endday = map2.get("endday");
//                 if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
//                	 xmnr +="从"+startday+"到"+endday;
//                 }
//    			 ExcelUtil.modiStrCell2(wsOne,0, 3, xmnr==null?"":xmnr, wcfxmnr);//项目内容
//                 String fzsj = map2.get("gzsj");
//                 String year="";
//                 String month="";
//                 String day="";
//                 if(fzsj!=null && fzsj.length()>4){
//                	 year = fzsj.substring(0, 4);
//                	 month = fzsj.substring(5, 7);
//                	 day = fzsj.substring(8, 10);
//        			 ExcelUtil.modiStrCell2(wsOne,10, 7, year==null?"":year, wcf2);//变更盖章年
//        			 ExcelUtil.modiStrCell2(wsOne,13, 7, month==null?"":month, wcf2);//变更盖章月
//        			 ExcelUtil.modiStrCell2(wsOne,15, 7, day==null?"":day, wcf2);//变更盖章日
//                 }
//                 if(list2.size()>4){
//                	 map2 =(Map<String, String>) list2.get(4);
//                	 xmnr =map2.get("xmnr");
//                     xmnr = xmnr.replaceAll("<br>", "\r\n");
//                     xmnr = xmnr.replaceAll("&nbsp;", " ");
//                     xmnr +="\r\n  有效期限：";
//                     startday = map2.get("startday");
//                     endday = map2.get("endday");
//                     if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
//                    	 xmnr +="从"+startday+"到"+endday;
//                     }
//        			 ExcelUtil.modiStrCell2(wsOne,0, 9, xmnr==null?"":xmnr, wcfxmnr);//项目内容
//                     fzsj = map2.get("gzsj");
//                     year="";
//                     month="";
//                     day="";
//                     if(fzsj!=null && fzsj.length()>0){
//                    	 year = fzsj.substring(0, 4);
//                    	 month = fzsj.substring(5, 7);
//                    	 day = fzsj.substring(8, 10);
//            			 ExcelUtil.modiStrCell2(wsOne,10, 16, year==null?"":year, wcf2);//变更盖章年
//            			 ExcelUtil.modiStrCell2(wsOne,13, 16, month==null?"":month, wcf2);//变更盖章月
//            			 ExcelUtil.modiStrCell2(wsOne,15, 16, day==null?"":day, wcf2);//变更盖章日
//                     }
//                 }
//                 if(list2.size()>5){
//                	 map2 =(Map<String, String>) list2.get(5);
//                	 xmnr =map2.get("xmnr");
//                     xmnr = xmnr.replaceAll("<br>", "\r\n");
//                     xmnr = xmnr.replaceAll("&nbsp;", " ");
//                     xmnr +="\r\n  有效期限：";
//                     startday = map2.get("startday");
//                     endday = map2.get("endday");
//                     if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
//                    	 xmnr +="从"+startday+"到"+endday;
//                     }
//        			 ExcelUtil.modiStrCell2(wsOne,0, 19, xmnr==null?"":xmnr, wcfxmnr);//项目内容
//                     fzsj = map2.get("gzsj");
//                     year="";
//                     month="";
//                     day="";
//                     if(fzsj!=null && fzsj.length()>0){
//                    	 year = fzsj.substring(0, 4);
//                    	 month = fzsj.substring(5, 7);
//                    	 day = fzsj.substring(8, 10);
//            			 ExcelUtil.modiStrCell2(wsOne,10, 26, year==null?"":year, wcf2);//变更盖章年
//            			 ExcelUtil.modiStrCell2(wsOne,13, 26, month==null?"":month, wcf2);//变更盖章月
//            			 ExcelUtil.modiStrCell2(wsOne,15, 26, day==null?"":day, wcf2);//变更盖章日
//                     }
//                 }
//             }
//             
		} catch (Exception e) {
			e.printStackTrace();
		} 
         
        
    }
    
    /**
     * 写数据
     * @param wsOne
     * @param form
     */
    private void copyFbData(WritableSheet wsOne, ShljYsForm form) {
    	 try {
    		 WritableCellFormat wcf=ExcelUtil.createCellFormat("宋体", 12, Alignment.LEFT, VerticalAlignment.CENTRE,false);
			 WritableCellFormat wcf1=ExcelUtil.createCellFormat("宋体", 12, Alignment.LEFT, VerticalAlignment.CENTRE,true);
			 WritableCellFormat wcf2=ExcelUtil.createCellFormat("宋体", 12, Alignment.LEFT, VerticalAlignment.CENTRE,false);
			 WritableCellFormat wcf3=ExcelUtil.createCellFormat("宋体", 12, Alignment.LEFT, VerticalAlignment.TOP,false);
			 WritableCellFormat wcfdate=ExcelUtil.createCellFormat("宋体", 8, Alignment.LEFT, VerticalAlignment.CENTRE,false);
			 WritableCellFormat wcfxmnr=ExcelUtil.createCellFormat("宋体", 10, Alignment.LEFT, VerticalAlignment.TOP,true);
			 WritableCellFormat wcfxmrq=ExcelUtil.createCellFormat("宋体", 10, Alignment.RIGHT, VerticalAlignment.CENTRE,false);
			 wcf.setLocked(false);
			 wcf1.setLocked(false);
			 wcf2.setLocked(false);
			 wcf3.setLocked(false);
			 wcfdate.setLocked(false);
			 ExcelUtil.modiStrCell2(wsOne, 1, 1, form.getSqdw()==null?"":form.getSqdw(), wcf);//申请单位
			 ExcelUtil.modiStrCell2(wsOne,1, 2, form.getAddress()==null?"":form.getAddress(), wcf1);//地址
			 ExcelUtil.modiStrCell2(wsOne,1, 4, form.getYyzch()==null?"":form.getYyzch(), wcf);//营业执照注册号
			 ExcelUtil.modiStrCell2(wsOne,1, 5, form.getZczb()==null?"":form.getZczb(), wcf);//注册资本
			 ExcelUtil.modiStrCell2(wsOne,1, 7, form.getFddbr()==null?"":form.getFddbr(), wcf2);//法定代表人
			 ExcelUtil.modiStrCell2(wsOne,8, 7, form.getFddbrZw()==null?"":form.getFddbrZw(), wcf2);//职务
			 ExcelUtil.modiStrCell2(wsOne,17, 7, form.getFddbrZc()==null?"":form.getFddbrZc(), wcf2);//职称
			 ExcelUtil.modiStrCell2(wsOne,1, 9, form.getQyManager()==null?"":form.getQyManager(), wcf2);//企业负责人
			 ExcelUtil.modiStrCell2(wsOne,8, 9,form.getQyMaangerZw()==null?"":form.getQyMaangerZw(), wcf2);//职务
			 ExcelUtil.modiStrCell2(wsOne,17, 9,form.getQyManagerZc()==null?"":form.getQyManagerZc(), wcf2);//职称
			 if("1".equals(form.getQylx())){//内资企业
				  ExcelUtil.modiStrCell2(wsOne,1, 11,"√", wcf2);//企业类型内资
			 }else if ("2".equals(form.getQylx())){
				  ExcelUtil.modiStrCell2(wsOne,9, 11,"√", wcf2);//企业类型 港澳台
			 } else if ("2".equals(form.getQylx())){
			  ExcelUtil.modiStrCell2(wsOne,1, 12,"√", wcf2);//企业类型 外商
			}else if ("2".equals(form.getQylx())){
			  ExcelUtil.modiStrCell2(wsOne,9, 12,"√", wcf2);//企业类型 台资
			}
      
			 ExcelUtil.modiStrCell2(wsOne,2, 15, form.getQygyzb()==null?"":form.getQygyzb(), wcf2);//企业资本构成比例 国有
			 ExcelUtil.modiStrCell2(wsOne,11, 15, form.getQygrzb()==null?"":form.getQygrzb(), wcf2);//企业资本构成比例 个人
			 ExcelUtil.modiStrCell2(wsOne,2, 16, form.getQywszb()==null?"":form.getQywszb(), wcf2);//企业资本构成比例 外商
			 ExcelUtil.modiStrCell2(wsOne,13, 16, form.getQyhzzb()==null?"":form.getQyhzzb(), wcf2);//企业资本构成比例 港澳
			 
			 ExcelUtil.modiStrCell2(wsOne,1, 19, "广州市（水域）城市生活垃圾经营性清扫（捞）、收集服务", wcf2);//许可正内容
			 
			 ExcelUtil.modiStrCell2(wsOne,1, 21, form.getFzjg()==null?"":form.getFzjg(), wcf2);//许可发证机关
			 
			 ExcelUtil.modiStrCell2(wsOne,15, 22, form.getJdTel()==null?"":form.getJdTel(), wcf2);//监督电话
			 
			 ExcelUtil.modiStrCell2(wsOne,1, 24, form.getStartYear()==null?"":form.getStartYear(), wcf2);//许可正发证日期

			 ExcelUtil.modiStrCell2(wsOne,4, 24, form.getStartMonth()==null?"":form.getStartMonth(), wcf2);//许可正发证日期

			 ExcelUtil.modiStrCell2(wsOne,7, 24, form.getStartDay()==null?"":form.getStartDay(), wcf2);//许可正发证日期
      
			 ExcelUtil.modiStrCell2(wsOne,10, 24, form.getEndYear()==null?"":form.getEndYear(), wcf2);//许可正发证日期

			 ExcelUtil.modiStrCell2(wsOne,13, 24, form.getEndMonth()==null?"":form.getEndMonth(), wcf2);//许可正发证日期

			 ExcelUtil.modiStrCell2(wsOne,16, 24, form.getEndDay()==null?"":form.getEndDay(), wcf2);//许可正发证日期
      
			 ExcelUtil.modiStrCell2(wsOne,1, 26, form.getFzrq()==null?"":form.getFzrq(), wcf2);//许可正发证日期
			 ExcelUtil.modiStrCell2(wsOne,18, 26, form.getZsbh()==null?"":form.getZsbh(), wcf2);//许可正发证日期
			 
			 ExcelUtil.modiStrCell2(wsOne,22, 3, form.getXmnr1()==null?"":form.getXmnr1(), wcfxmnr);//项目记录1
			  if(StringUtils.isNotBlank(form.getGzsj1())){
				 String fzsj=form.getGzsj1();
             	 String year = fzsj.substring(0, 4);
             	 String month = fzsj.substring(5, 7);
             	 String day = fzsj.substring(8, 10);
     			 ExcelUtil.modiStrCell2(wsOne,27, 6, year==null?"":year, wcfxmrq);//项目盖章年
     			 ExcelUtil.modiStrCell2(wsOne,29, 6, month==null?"":month, wcfxmrq);//项目盖章月
     			 ExcelUtil.modiStrCell2(wsOne,31, 6, day==null?"":day, wcfxmrq);//项目盖章日
     			String startday = form.getStartday1();
                String endday = form.getEndday1();
                if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
               	 String date="有效期从"+startday+"到"+endday;
                 ExcelUtil.modiStrCell2(wsOne,22, 5, date, wcfxmnr);//项目内容时间
                }
              }
			  
			  ExcelUtil.modiStrCell2(wsOne,22, 9, form.getXmnr2()==null?"":form.getXmnr2(), wcfxmnr);//项目记录2
			  if(StringUtils.isNotBlank(form.getGzsj2())){
				 String fzsj=form.getGzsj2();
             	 String year = fzsj.substring(0, 4);
             	 String month = fzsj.substring(5, 7);
             	 String day = fzsj.substring(8, 10);
     			 ExcelUtil.modiStrCell2(wsOne,27, 17, year==null?"":year, wcfxmrq);//项目盖章年
     			 ExcelUtil.modiStrCell2(wsOne,29, 17, month==null?"":month, wcfxmrq);//项目盖章月
     			 ExcelUtil.modiStrCell2(wsOne,31, 17, day==null?"":day, wcfxmrq);//项目盖章日
     			 String startday = form.getStartday2();
     			 String endday = form.getEndday2();
     			 if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
     				 String date="有效期从"+startday+"到"+endday;
     				 ExcelUtil.modiStrCell2(wsOne,22, 15, date, wcfxmnr);//项目内容时间
     			 }
              }
					  
			 ExcelUtil.modiStrCell2(wsOne,22, 21, form.getXmnr3()==null?"":form.getXmnr3(), wcfxmnr);//项目记录3
			 if(StringUtils.isNotBlank(form.getGzsj3())){
				 String fzsj=form.getGzsj3();
             	 String year = fzsj.substring(0, 4);
             	 String month = fzsj.substring(5, 7);
             	 String day = fzsj.substring(8, 10);
     			 ExcelUtil.modiStrCell2(wsOne,27, 27, year==null?"":year, wcfxmrq);//项目盖章年
     			 ExcelUtil.modiStrCell2(wsOne,29, 27, month==null?"":month, wcfxmrq);//项目盖章月
     			 ExcelUtil.modiStrCell2(wsOne,31, 27, day==null?"":day, wcfxmrq);//项目盖章日
     			 String startday = form.getStartday3();
     			 String endday = form.getEndday3();
     			 if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
     				 String date="有效期从"+startday+"到"+endday;
     				 ExcelUtil.modiStrCell2(wsOne,22, 24, date, wcfxmnr);//项目内容时间
     			 }
			 }

//             List list2 =new ArrayList();
//             list2 = ywHwXminfoService.getFbXminfo(form.getId(), "shljys");
//             if(list2!=null && list2.size()>0){
//                 Map<String, String> map2 =(Map<String, String>) list2.get(0);
//                 String xmnr =map2.get("xmnr");
//                 xmnr = xmnr.replaceAll("<br>", "\r\n");
//                 xmnr = xmnr.replaceAll("&nbsp;", " ");
//                 xmnr +="\r\n  有效期限：";
//                 String startday = map2.get("startday");
//                 String endday = map2.get("endday");
//                 if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
//                	 xmnr +="从"+startday+"到"+endday;
//                 }
//    			 ExcelUtil.modiStrCell2(wsOne,22, 2, xmnr==null?"":xmnr, wcfxmnr);//项目内容
//                 String fzsj = map2.get("gzsj");
//                 String year="";
//                 String month="";
//                 String day="";
//                 if(fzsj!=null && fzsj.length()>0){
//                	 year = fzsj.substring(0, 4);
//                	 month = fzsj.substring(5, 7);
//                	 day = fzsj.substring(8, 10);
//        			 ExcelUtil.modiStrCell2(wsOne,27, 5, year==null?"":year, wcfxmrq);//变更盖章年
//        			 ExcelUtil.modiStrCell2(wsOne,29, 5, month==null?"":month, wcfxmrq);//变更盖章月
//        			 ExcelUtil.modiStrCell2(wsOne,31, 5, day==null?"":day, wcfxmrq);//变更盖章日
//                 }
//                 if(list2.size()>1){
//                	 map2 =(Map<String, String>) list2.get(1);
//                	 xmnr =map2.get("xmnr");
//                     xmnr = xmnr.replaceAll("<br>", "\r\n");
//                     xmnr = xmnr.replaceAll("&nbsp;", " ");
//                     xmnr +="\r\n  有效期限：";
//                     startday = map2.get("startday");
//                     endday = map2.get("endday");
//                     if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
//                    	 xmnr +="从"+startday+"到"+endday;
//                     }
//        			 ExcelUtil.modiStrCell2(wsOne,22, 8, xmnr==null?"":xmnr, wcfxmnr);//项目内容
//                     fzsj = map2.get("gzsj");
//                     year="";
//                     month="";
//                     day="";
//                     if(fzsj!=null && fzsj.length()>0){
//                    	 year = fzsj.substring(0, 4);
//                    	 month = fzsj.substring(5, 7);
//                    	 day = fzsj.substring(8, 10);
//            			 ExcelUtil.modiStrCell2(wsOne,27, 16, year==null?"":year, wcfxmrq);//变更盖章年
//            			 ExcelUtil.modiStrCell2(wsOne,29, 16, month==null?"":month, wcfxmrq);//变更盖章月
//            			 ExcelUtil.modiStrCell2(wsOne,31, 16, day==null?"":day, wcfxmrq);//变更盖章日
//                     }
//                 }
//                 if(list2.size()>2){
//                	 map2 =(Map<String, String>) list2.get(1);
//                	 xmnr =map2.get("xmnr");
//                     xmnr = xmnr.replaceAll("<br>", "\r\n");
//                     xmnr = xmnr.replaceAll("&nbsp;", " ");
//                     xmnr +="\r\n  有效期限：";
//                     startday = map2.get("startday");
//                     endday = map2.get("endday");
//                     if(startday!=null && startday.length()>0 && endday!=null && endday.length()>0){
//                    	 xmnr +="从"+startday+"到"+endday;
//                     }
//        			 ExcelUtil.modiStrCell2(wsOne,22, 20, xmnr==null?"":xmnr, wcfxmnr);//项目内容
//                     fzsj = map2.get("gzsj");
//                     year="";
//                     month="";
//                     day="";
//                     if(fzsj!=null && fzsj.length()>0){
//                    	 year = fzsj.substring(0, 4);
//                    	 month = fzsj.substring(5, 7);
//                    	 day = fzsj.substring(8, 10);
//            			 ExcelUtil.modiStrCell2(wsOne,27, 26, year==null?"":year, wcfxmrq);//变更盖章年
//            			 ExcelUtil.modiStrCell2(wsOne,29, 26, month==null?"":month, wcfxmrq);//变更盖章月
//            			 ExcelUtil.modiStrCell2(wsOne,31, 26, day==null?"":day, wcfxmrq);//变更盖章日
//                     }
             //   }
             //}
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    public String wfBusYslTuih(ShljYsBaForm form,LoginUserForm loginUser) throws Exception {
    	String  loginUserName = loginUser.getUser().getUserName();
    	WfBusInstanceTaskForm taskForm = new WfBusInstanceTaskForm();
		taskForm.setHandleComments("资料不全，不予受理。");
		//把审批状态数据保存到ywWebserviceInfo ，交换给方欣
		ywWebserviceInfoService.saveYwWebserviceInfo(form.getSqrq(), form.getAcceptNo(), form.getCbyw(), form.getJbrxm(), form.getSjr(), form.getSqdw(), 
				form.getBusinessCode(), form.getApprovalNo(), loginUserName, loginUser.getOrg().getOrgName(), "ysl", new Date(), false, "预受理", taskForm);
//		System.out.println("form.getYslThyy() = "+java.net.URLDecoder.decode(form.getYslThyy(),"UTF-8"));
		this.changeYslState(form.getId(), 0L,taskForm.getHandleComments());
		
		//（网办）交换到市民网页
		Map map=exchangeStateService.buildMap(loginUser, null, form.getId().toString(), form.getTemplateCode(), false);
		String durationExpression = wfServiceEX.getDurationExpressionByTemplateCode(form.getTemplateCode());
		ywWebserviceForWbService.setValueAndSaveYwWebserviceForWb(loginUserName,form.getTemplateCode(),
				form.getId().toString(),durationExpression,"001",taskForm.getHandleComments(), map);
    	return null;
    }
}
